import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: happyiu
 * Date: 2022-01-24
 * Time: 8:19
 * Description:
 */
public class TestDemo {

    public static void main1(String[] args) {
        int [] array ={1,2,3};
        System.out.println(array[5]);
        System.out.println("我不能打印出来了");
    }

    public static void main2(String[] args) {
        int [] array ={1,2,3};
        try{
            System.out.println(array[5]);
            System.out.println("我不能打印出来了");
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("我捕捉到了一个数组越界异常！！");
        }
            System.out.println("我在这可以打印");

    }

    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int arr = scanner.nextInt();
        System.out.println(arr);
    }

    public static void main4(String[] args) {
        int [] array ={1,2,3};
        try{
            array = null;
            System.out.println(array[2]);
            System.out.println("我不能打印出来了");
        }catch (ArrayIndexOutOfBoundsException e){
            e.printStackTrace();
            System.out.println("我捕捉到了一个数组越界异常！！");
        }catch (NullPointerException e){
            e.printStackTrace();
            System.out.println("我捕捉到了一个空指针异常！！");
        }
        System.out.println("我在这可以打印");

    }


    public static void main5(String[] args) {
        int [] array ={1,2,3};
        try{
            System.out.println(array[5]);
            System.out.println("111111");
        }catch (IndexOutOfBoundsException e){
            e.printStackTrace();
            System.out.println("我捕捉到了一个数组越界异常！！");
        }

        System.out.println("222222");

    }

    public static void main6(String[] args) {
        Scanner scanner = new Scanner(System.in);

        try{
            int arr = scanner.nextInt();
            System.out.println(arr);
        }catch (InputMismatchException e){
            e.printStackTrace();
            System.out.println("输入有误！");
        }catch (ArithmeticException e){
            e.printStackTrace();
            System.out.println("算数异常，可能是0作为除数");
        }finally{
            //一般用作 资源的关闭
            scanner.close();
            System.out.println("finally执行了");
        }

    }

    public static void main(String[] args) {
        try {
            func();
        } catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
        }
        System.out.println("after try catch");
    }
    public static void func() {
        int[] arr = {1, 2, 3};
        System.out.println(arr[100]);
    }


}





















